<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="../templates/principal.xhtml">

    <ui:define name="content" id="content">        
        <h:form id="frmPropostaEmail">
            <p:growl id="messages" life="5000" />

            <p:panel id="panel" header="Bem Vindo ao Cadastro de Modelo de E-Mail">

                <p:dataTable id="tabPropostaEmail" widgetVar="wtabPropostaEmail" var="propostaEmail" value="#{propostaEmailBean.lazyModel}" paginator="true" rows="15" 
                             paginatorPosition="top" emptyMessage="Nenhum Registro Retornado ..." lazy="true" filterEvent="enter">

                    <p:column headerText="Descrição" sortBy="#{propostaEmail.dscEmail}" filterBy="#{propostaEmail.dscEmail}" style="text-align: left">
                        <h:outputText value="#{propostaEmail.dscEmail}" />
                    </p:column>

                    <p:column style="width: 100px;">
                        <h:panelGrid columns="4" styleClass="actions" cellpadding="0">
                            <p:commandButton id="selectButton" update=":frmPropostaEmail:panel, :frmPropostaEmail:messages" 
                                             icon="ui-icon-search" title="Visualizar // Alterar Modelo de E-Mail" oncomplete="PF('propostaEmailDialog').show()">
                                <f:setPropertyActionListener value="#{propostaEmail}" target="#{propostaEmailBean.selectedPropostaEmail}" />
                                <f:setPropertyActionListener value="#{false}" target="#{propostaEmailBean.altera}" />
                            </p:commandButton>

                            <p:commandButton id="excluirButton" update=":frmPropostaEmail:panel, :frmPropostaEmail:messages" 
                                             icon="ui-icon-trash" title="Excluir Modelo de E-Mail" oncomplete="PF('confirmation').show()">
                                <f:setPropertyActionListener value="#{propostaEmail}" target="#{propostaEmailBean.selectedPropostaEmail}" />
                            </p:commandButton>
                        </h:panelGrid>
                    </p:column>

                    <f:facet name="footer">
                        <div style="text-align: left;">
                            <p:commandButton id="incluirButton" actionListener="#{propostaEmailBean.preparaInserir}" 
                                             update=":frmPropostaEmail:panel, :frmPropostaEmail:messages"  value="Novo Modelo de E-Mail"
                                             icon="ui-icon-pencil" title="Cadastrar Novo Modelo de E-Mail" oncomplete="PF('propostaEmailDialog').show()" />
                        </div>
                    </f:facet>
                </p:dataTable>

                <p:dialog id="dialogPropostaEmail" header="Detalhes Modelo de E-Mail" widgetVar="propostaEmailDialog" resizable="true" dynamic="true"
                          width="1300" showEffect="explode" hideEffect="explode" style="text-align: left;" position="top">
                    <p:panel id="panelPropostaEmail">
                        <p:panelGrid id="displayPropostaEmail">
                            <p:row>
                                <p:column>
                                    <h:outputText value="Descrição:" />
                                </p:column>
                                <p:column>
                                    <p:inputText id="inDescricao" value="#{propostaEmailBean.selectedPropostaEmail.dscEmail}" maxlength="50" style="width:500px; font-weight:bold; " />
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputText value="Macros:" />
                                </p:column>
                                <p:column>
                                    <p:selectOneRadio id="customRadioMacro" value="#{propostaEmailBean.itemmacro}" layout="custom">
                                        <f:selectItem itemLabel="Option 1" itemValue="#NOME_CLIENTE#" />
                                        <f:selectItem itemLabel="Option 2" itemValue="#ENDERECO_CLIENTE#" />
                                        <f:selectItem itemLabel="Option 3" itemValue="#NOME_EMPREENDIMENTO#" />
                                        <p:ajax listener="#{propostaEmailBean.inserirMacro()}" update=":frmPropostaEmail:displayPropostaEmail" process="@this" />
                                    </p:selectOneRadio>
                                    <p:panelGrid>
                                        <p:row>
                                            <p:column>
                                                <p:radioButton id="opt4" for="customRadioMacro" itemIndex="0" />
                                            </p:column>
                                            <p:column>
                                                <h:outputText value="Nome do Cliente:" />
                                            </p:column>
                                            
                                            <p:column>
                                                <p:radioButton id="opt5" for="customRadioMacro" itemIndex="1" />
                                            </p:column>
                                            <p:column>
                                                <h:outputText value="Endereço do Cliente:" />
                                            </p:column>
                                            
                                            <p:column>
                                                <p:radioButton id="opt6" for="customRadioMacro" itemIndex="2" />
                                            </p:column>
                                            <p:column>
                                                <h:outputText value="Nome do Empreendimento:" />
                                            </p:column>
                                        </p:row>
                                    </p:panelGrid>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputText value="Logos:" style="width: 150px;"/>
                                </p:column>
                                <p:column>
                                    <p:selectOneRadio id="customRadio" value="#{propostaEmailBean.itemlogo}" layout="custom">
                                        <f:selectItem itemLabel="Option 1" itemValue="#{request.contextPath}/logo/patricia_triunfo.png" />
                                        <f:selectItem itemLabel="Option 2" itemValue="#{request.contextPath}/logo/patricia_consultoria.png" />
                                        <f:selectItem itemLabel="Option 3" itemValue="#{request.contextPath}/logo/patricia_rodape.png" />
                                        <p:ajax listener="#{propostaEmailBean.inserirLogo()}" update=":frmPropostaEmail:displayPropostaEmail" process="@this" />
                                    </p:selectOneRadio>
                                    <p:panelGrid>
                                        <p:row>
                                            <p:column>
                                                <h:outputText value="Triunfo:" />
                                            </p:column>
                                            <p:column>
                                                <p:radioButton id="opt1" for="customRadio" itemIndex="0" />
                                            </p:column>
                                            <p:column>
                                                <p:graphicImage value="/logo/patricia_triunfo_modelo.png" />
                                            </p:column>
                                            <p:column>
                                                <h:outputText value="Patricia Consultoria:" />
                                            </p:column>
                                            <p:column>
                                                <p:radioButton id="opt2" for="customRadio" itemIndex="1" />
                                            </p:column>
                                            <p:column>
                                                <p:graphicImage value="/logo/patricia_consultoria_modelo.png" />
                                            </p:column>
                                        </p:row>
                                        <p:row>
                                            <p:column>
                                                <h:outputText value="Rodapé:" />
                                            </p:column>
                                            <p:column>
                                                <p:radioButton id="opt3" for="customRadio" itemIndex="2" />
                                            </p:column>
                                            <p:column colspan="4">
                                                <p:graphicImage value="/logo/patricia_rodape_modelo.png"  width="100%"/>
                                            </p:column>
                                        </p:row>
                                    </p:panelGrid>
                                </p:column>
                            </p:row>
                            <p:row>
                                <p:column>
                                    <h:outputText value="Corpo do E-Mail:" />
                                </p:column>
                                <p:column>
                                    <p:editor id="editorModelo" value="#{propostaEmailBean.selectedPropostaEmail.email}" width="1100" height="400" />
                                </p:column>
                            </p:row>
                            <f:facet name="footer">
                                <p:row>
                                    <p:column colspan="2">
                                        <p:commandButton value="Inserir" update=":frmPropostaEmail:panel, :frmPropostaEmail:messages" rendered="#{propostaEmailBean.altera}"
                                                         icon="ui-icon-disk" actionListener="#{propostaEmailBean.inserir}" oncomplete="PF('propostaEmailDialog').hide()" />
                                        <p:commandButton value="Alterar" update=":frmPropostaEmail:panel, :frmPropostaEmail:messages" rendered="#{!propostaEmailBean.altera}"
                                                         icon="ui-icon-disk" actionListener="#{propostaEmailBean.alterar}" oncomplete="PF('propostaEmailDialog').hide()" />
                                    </p:column>
                                </p:row>
                            </f:facet>
                        </p:panelGrid>     


                    </p:panel>
                </p:dialog>

                <p:dialog header="Confirma a Exclusão desse Modelo de E-Mail: #{propostaEmailBean.selectedPropostaEmail.dscEmail}? " widgetVar="confirmation">  

                    <p:commandButton value="Sim" update=":frmPropostaEmail:panel, :frmPropostaEmail:messages" oncomplete="PF('confirmation').hide(), PF('propostaEmailDialog').hide()"
                                     actionListener="#{propostaEmailBean.excluir}" />  
                    <p:commandButton value="Não" onclick="PF('confirmation').hide()" type="button" />   

                </p:dialog>


            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>